home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / thor / DBatchFTP.lha / DBatchFTP_v1.0 / DBatchFTP.thor < prev   
Encoding:
Text File  |  1997-08-08  |  5.2 KB  |  157 lines

  1. /*
  2. ** $VER: DBatchFTP.thor 1.0 (07.08.97)
  3. **
  4. ** ############################ DBatchFTP.thor ############################
  5. ** ######################## by David Stroud (Newt) ########################
  6. ** ############################# Version 1.00 #############################
  7. **
  8. ** The basis for this script came from CalcDL.thor by Eirik Nicolai Synnes,
  9. ** to whom I must extend my thanks in making the task somewhat easier!
  10. **
  11. ** I also made use of AutoReply.br for the event creation. Thanks to Neil
  12. ** Bothwick for that script :)
  13. **
  14. ** This is my first ARexx script ever, so if I've done anything wrong or
  15. ** silly, please excuse me.  Any suggestions/comments are gratefully
  16. ** received.  Email me at:
  17. **
  18. **                      DaveStroud@nebula.demon.co.uk
  19. **
  20. ** ...or make your feelings known on the Thor Mailing list so everyone
  21. ** can have a laugh at my ARexx scripting technique :)
  22. */
  23.  
  24. /**************************************************************************
  25. ** Please change the following variables to suit your configuration...   **
  26. **************************************************************************/
  27.  
  28. /* aminet_server: No trailing colon! *************************************/
  29. /* aminet_basedir: Please include leading and trailing slashes. **********/
  30. /* demon_bftp: Address for batch FTP requests to be sent. ****************/
  31. /* email_conf: The name of your main Email conference on your system *****/
  32.  
  33. aminet_server   = "ftp.uk.aminet.org"
  34. aminet_basedir  = "/pub/aminet/"
  35. demon_bftp      = "ftp@demon.net"
  36. email_conf_name = "Email"
  37.  
  38. /* ########################################################################
  39. ** ############### DO NOT EDIT ANYTHING BELOW THIS LINE! ##################
  40. ** ########################################################################
  41. */
  42.  
  43. options results
  44.  
  45. /* Find Thor and BBSREAD ARexx ports' */
  46. p=address()||' '||show('P',,)
  47. if pos(' THOR.',p)>0 then thorport=word(substr(p,pos(' THOR.',p)),1)
  48. else do
  49.      say 'No THOR port found!'
  50.      exit(0)
  51.      end
  52. if ~show('p', 'BBSREAD') then do
  53.      address command
  54.      "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  55.      "WaitForPort BBSREAD"
  56.      end
  57.  
  58. address(thorport)
  59. 'CURRENTSYSTEM STEM 'curbbs
  60. if rc > 1 then do
  61.     'REQUESTNOTIFY "CURRENTSYSTEM: 'THOR.LASTERROR'" "Ok"'
  62.     exit(0)
  63.     end
  64.  
  65. address(bbsread)
  66. 'GETBBSDATA BBSNAME "'curbbs.BBSNAME'" STEM 'bbsdata
  67. if rc ~= 0 then do
  68.     address(thorport)
  69.     'REQUESTNOTIFY "GETBBSDATA: 'BBSREAD.LASTERROR'" "Ok"'
  70.     exit(0)
  71.     end
  72.  
  73. /* Temporary counter and file-opened indicator*/
  74. tcount = 0
  75. tfile = 0
  76.  
  77. /* If there's any events */
  78. if bbsdata.NUMEVENT > 0 then do eventnum = bbsdata.FIRSTEVENT to bbsdata.LASTEVENT
  79.  
  80.     /* examine an event's data */
  81.     address(bbsread)
  82.     'READBREVENT BBSNAME "'curbbs.BBSNAME'" EVENTNR 'eventnum' TAGSSTEM ETAG DATASTEM' EDATA
  83.  
  84.     /* if not successful, exit showing error */
  85.     if rc ~= 0 then do
  86.         address(thorport)
  87.         'REQUESTNOTIFY "READBREVENT: 'BBSREAD.LASTERROR'" "Ok"'
  88.         exit(0)
  89.         end
  90.  
  91.     /* Debugging bit (pretend you didn't notice ;)
  92.     ** say 'Event Num   :' eventnum
  93.     ** say ' Event flags:' c2x(EDATA.FLAGS)
  94.     ** say ' Event type :' EDATA.EVENTTYPE
  95.     */
  96.  
  97.     /* otherwise, do this... */
  98.     /* if the event is a download */
  99.     if EDATA.EVENTTYPE = 4 then do
  100.  
  101.     /* Another debug bit
  102.     ** say eventnum bittst(EDATA.FLAGS, 0) bittst(EDATA.FLAGS, 1) bittst(EDATA.FLAGS, 2) bittst(EDATA.FLAGS, 3) bittst(EDATA.FLAGS, 4) bittst(EDATA.FLAGS, 5) bittst(EDATA.FLAGS, 6)
  103.     */
  104.         /* say c2x(EDATA.FLAGS) */
  105.         if ~bittst(edata.FLAGS, 0) & bittst(edata.FLAGS, 5) then do
  106.  
  107.             if ~(ETAG.DIRECTORY = 'ETAG.DIRECTORY') then do
  108.  
  109.                 if tfile=0 then do
  110.                     /* Create message file for reply */
  111.                     address(bbsread)
  112.                     UNIQUEMSGFILE bbsname '"'curbbs.BBSNAME'"' stem MsgFile
  113.                     if ~open(out,MsgFile.NAME,'w') then do
  114.                         address(thorport)
  115.                         'REQUESTNOTIFY "Could not open file for data!\n\nI know, this shouldn`t happen." "Erk!"'
  116.                         exit(0)
  117.                         end
  118.                     tfile=1
  119.                     end
  120.                 /* write the event to the datafile in the batchftp format */
  121.                 call writeln(out,''aminet_server':'aminet_basedir''ETAG.DIRECTORY'/'ETAG.FILENAME'')
  122.                 tcount=tcount+1
  123.                 end
  124.             end
  125.         end
  126.     end
  127.  
  128. /* Close file */
  129. call close(out)
  130.  
  131. EventData.TOADDR     = demon_bftp
  132. EventData.SUBJECT    = 'Batch-FTP request'
  133. EventData.CONFERENCE = email_conf_name
  134. EventData.MSGFILE    = MsgFile.FILEPART
  135. EventData.TONAME     = 'Demon Batch-FTP'
  136.  
  137. if tfile=1 then do
  138. WRITEBREVENT bbsname '"'curbbs.BBSNAME'"' event 0 stem EventData
  139. if RC > 0 then do
  140.     address(thorport)
  141.     'REQUESTNOTIFY "Houston, we have a problem:\n\nWRITEBREVENT returned: 'RC'" "Poohsticks."'
  142.     exit(0)
  143.     end
  144. end
  145.  
  146. if tcount=0 then do
  147.     address(thorport)
  148.     'REQUESTNOTIFY "No frozen download events were\n picked up by DBatchFTP.thor!" "Hmmm, okay."'
  149.     exit(0)
  150.     end
  151.  
  152. address(thorport)
  153. 'REQUESTNOTIFY "        DBatchFTP.thor has finished!        \n\nA total of 'tcount' download event(s) were transmogrified." "Smokin!"'
  154.  
  155. exit(0)
  156.  
  157.